<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Admin Users Controller
 *
 * Handles all the users
 *
 * @package		68kb
 * @subpackage	Admin_Controllers
 * @category	Admin_Controllers
 * @author		68kb Dev Team
 * @link		http://68kb.com/user_guide/overview/users.html
 * @version 	$Id: users.php 134 2009-12-02 01:29:40Z suzkaw68 $
 */
class Users extends CI_Controller
{
    /**
	* Constructor
	*
	* Requires needed models and helpers.
	* 
	* @access	public
	*/
    function __construct()
    {
        parent::__construct();
        $this->load->model('init_model');
        //$this->load->model('user_model');
        $this->load->helper('cookie');
		$this->load->library('auth');
		$this->auth->restrict();
    }
    
    /**
	* Index Controller
	*
	* Redirects to this->grid
	*
	* @access	public
	*/
    function index()
    {
        $data = '';
        redirect('backend/users/grid/');
    }
    
    /**
	* Grid
	*
	* Show a table of users
	* 
	* It assume this uri sequence:
	* /controller/simplepagination/[offset] 
	* or 
	* /controller/simplepagination/orderby/fieldname/orientation/[offset]
	*
	* @link http://codeigniter.com/forums/viewthread/45709/#217816
	* @access	public
	* @return	array
	*/
    function grid()
    {
        $data['nav'] = 'users';
		if ( ! $this->auth->check_level(1))
		{
			$data['not_allowed'] = TRUE;
			$this->init_model->display_template('content', $data, 'admin'); 
			return FALSE;
		}
        
        #### settings ###
		$this->load->library("pagination");
		$this->load->helper("url");
			
		$config['per_page'] = $this->init_model->settings['max_search'];
        #### db init ###
        
        //total number of rows
		$config['total_rows'] = $this->db->count_all('users');
        //prepare active record for new query (with limit/offeset/orderby)
		$this->db->select('id, username, firstname, lastname, email, level');
		$this->db->from("users");
        $this->db->limit($config['per_page']);
        $query = $this->db->get();
		$data['items'] =  $query->result_array();
        
        $config['base_url'] = site_url('backend/users/grid');
		$config['uri_segment'] = 4;
		$this->pagination->initialize($config);
		$data["pagination"] = $this->pagination->create_links();	   
        
        $this->init_model->display_template('users/grid', $data, 'backend');
    }


    /**
	* Revert
	*
	* Show a message and redirect the user
	* 
	* @access	public
	* @param	string -- The location to goto
	* @return	array
	*/
    function revert($goto)
	{
		$data['goto'] = $goto;
		$data['nav'] = 'users';
		$this->init_model->display_template('content', $data, 'admin');
	}
}
/* End of file users.php */
/* Location: ./application/controllers/backend/users.php */ 